package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request/adminRequest"
	"exercise/application/yiran/app/service/admin"
	"github.com/gin-gonic/gin"
)

type floorController struct {
}

func (*floorController) List(ctx *gin.Context) {
	request := new(adminRequest.FloorListRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewFloorService().List(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*floorController) Add(ctx *gin.Context) {
	request := new(adminRequest.AddFloorRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	ret, err := admin.NewFloorService().Add(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*floorController) Edit(ctx *gin.Context) {
	request := new(adminRequest.EditFloorRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}

	err = admin.NewFloorService().Edit(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "编辑成功")
}

func (*floorController) Detail(ctx *gin.Context) {
	ret, err := admin.NewFloorService().Detail(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, ret)
}

func (*floorController) Deleted(ctx *gin.Context) {
	err := admin.NewFloorService().Deleted(ctx)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.OkToast(ctx, "删除成功")
}

func NewFloorController() *floorController {
	return &floorController{}
}
